<?
/**
 * VoiceOne Settings/Rules/timesegement/edit
 *
 * Frontend to provide access to the rules system in voiceone.
 * @package voiceone
 * @subpackage  settings_rules
 */
  include ("../../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  
  //================ PAGE LOGIC ================
  if (count($_POST)>0) {

    $id=$_POST["id"];
    $name=$_POST["name"];
    $date_from=implode("|",$_POST["date_from"]);
    $date_to=implode("|",$_POST["date_to"]);
    $hour_from=implode("|",$_POST["hour_from"]);
    $hour_to=implode("|",$_POST["hour_to"]);
    $week_day=@implode("|",$_POST["week_day"]);
    $day=@implode("|",$_POST["day"]);
    $month=@implode("|",$_POST["month"]);
    
    $entry=Array(
      "id" => $id,
      "name" => $name,
      "date_from" => $date_from,
      "date_to" => $date_to,
      "hour_from" => $hour_from,
      "hour_to" => $hour_to,
      "week_day" => $week_day,
      "day" => $day, 
      "month" => $month 
    );

    //save the group informations
    //echo "<pre>"; print_r($entry); echo "</pre>";
    $ret=$asterisk->putTimeSegment($entry);
    if ($ret>0) {
      $alert="<div class=\"AlertGood\">".$cwlang["timesegment"]["alertGood"]."</div>";
      $_GET["id"]=$ret;
    } else $alert="<div class=\"AlertBad\">".$cwlang["timesegment"]["alertBad"]."</div>";
    
    goToMainPage($alert);
  }
  //--------------------------------------------------------------------------
  
  $date_from=array();
  $date_to=array();
  $hour_from=array();
  $hour_to=array();
  $week_day=array();
  $day=array();
  $month=array();

  //if modify, read the group informations
  if (isset($_REQUEST["id"])) {
    $ret=$asterisk->getTimeSegment($_REQUEST["id"]);
    if ($err=$asterisk->getError()) die("Error: $err");
    $ret=$ret[0];
    $id=$ret["id"];
    $name=$ret["name"];
    $date_from=split("\|",$ret["date_from"]);
    $date_to=split("\|",$ret["date_to"]);
    $hour_from=split("\|",$ret["hour_from"]);
    $hour_to=split("\|",$ret["hour_to"]);
    $week_day=split("\|",$ret["week_day"]);
    $day=split("\|",$ret["day"]);
    $month=split("\|",$ret["month"]);
  }  


  
  //================ MAIN CONTENTS ================
  ob_start();
  ?>

  <?$sel="timesegment";include("../../navigation.php");?>
  
  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=$cwlang["timesegment"]["editTitle"]?></h1>
    <h3><a href="../" class="admin" ><?=$cwlang["isdngrp"]["return"]?></a></h3>
  </div>
  
  <div id="basic_form">
    <form action="<?=$PHP_SELF?><?if (isset($_GET["id"])) echo "?id=".$_GET["id"];?>" method="post" onSubmit="selectAll(getElementById('listRight')); return selectAll(getElementById('phonenumber'))">
      
    	<h2><?=$cwlang["timesegment"]["editSubTitle"]?></h2>
      <p class="blockintro"><?=$cwlang["timesegment"]["editSubTitleDesc"]?></p>
      <div class="block">
        <table >
          <tr><td></td><td colspan="3"><h3><?=$cwlang["timesegment"]["timesegInfo"]?></h3></td></tr>
          <tr>
            <td class="required"><label for="name"><?=$cwlang["timesegment"]["timesegName"]?>:</label></td>
            <td colspan="3"><input type="text" size="25" maxlength="30" id="name" name="name" value="<?=$name?>" /></td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><hr/></td></tr>

          <tr><td></td><td colspan="3"><h3><?=$cwlang["timesegment"]["timesegDate"]?></h3></td></tr>
          <tr>
            <td class="required"><label for="date_from[]"><?=$cwlang["timesegment"]["timesegFrom"]?>:</label></td>
            <td><input type="text" size="25" maxlength="30" id="date_from[]" name="date_from[]" value="<?=$date_from[0]?>" /></td>
            <td class="required"><label for="date_to[]"><?=$cwlang["timesegment"]["timesegTo"]?>:</label></td>
            <td><input type="text" size="25" maxlength="30" id="date_to[]" name="date_to[]" value="<?=$date_to[0]?>" /></td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><?=$cwlang["timesegment"]["timesegDateHelp"]?><hr/></td></tr>
          
          <tr><td></td><td colspan="3"><h3><?=$cwlang["timesegment"]["timesegHours"]?></h3></td></tr>
          <tr>
            <td class="required"><label for="hour_from[]"><?=$cwlang["timesegment"]["timesegFrom"]?>:</label></td>
            <td><input type="text" size="25" maxlength="30" id="hour_from[]" name="hour_from[]" value="<?=$hour_from[0]?>" /></td>
            <td class="required"><label for="hour_to[]"><?=$cwlang["timesegment"]["timesegTo"]?>:</label></td>
            <td><input type="text" size="25" maxlength="30" id="hour_to[]" name="hour_to[]" value="<?=$hour_to[0]?>" /></td>
          </tr>
          <tr>
            <td class="required"><label for="hour_from[]"><?=$cwlang["timesegment"]["timesegFrom"]?>:</label></td>
            <td><input type="text" size="25" maxlength="30" id="hour_from[]" name="hour_from[]" value="<?=$hour_from[1]?>" /></td>
            <td class="required"><label for="hour_to[]"><?=$cwlang["timesegment"]["timesegTo"]?>:</label></td>
            <td><input type="text" size="25" maxlength="30" id="hour_to[]" name="hour_to[]" value="<?=$hour_to[1]?>" /></td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><?=$cwlang["timesegment"]["timesegHoursHelp"]?><hr/></td></tr>
          
          <tr><td></td><td colspan="3"><h3><?=$cwlang["timesegment"]["timesegWeekDays"]?></h3></td></tr>
          <tr >
            <td class="required"><label for="week_day[]"><?=$cwlang["timesegment"]["timesegDays"]?>:</label></td>
            <td colspan="3">
              <table class="timesegment">
              <tr>
                <td><?=$cwlang["timesegment"]["timesegSu"]?> <input type="checkbox" id="week_day[]" name="week_day[]" value="1" <?if (in_array("1",$week_day)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegMo"]?> <input type="checkbox" id="week_day[]" name="week_day[]" value="2" <?if (in_array("2",$week_day)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegTu"]?> <input type="checkbox" id="week_day[]" name="week_day[]" value="3" <?if (in_array("3",$week_day)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegWe"]?> <input type="checkbox" id="week_day[]" name="week_day[]" value="4" <?if (in_array("4",$week_day)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegTh"]?> <input type="checkbox" id="week_day[]" name="week_day[]" value="5" <?if (in_array("5",$week_day)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegFr"]?> <input type="checkbox" id="week_day[]" name="week_day[]" value="6" <?if (in_array("6",$week_day)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegSa"]?> <input type="checkbox" id="week_day[]" name="week_day[]" value="7" <?if (in_array("7",$week_day)) echo "checked=\"checked\""; ?>/></td>
              </tr>
              </table>
            </td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><?=$cwlang["timesegment"]["timesegUnchecked"]?><hr/></td></tr>

          <tr><td></td><td colspan="3"><h3><?=$cwlang["timesegment"]["timesegMonthDays"]?></h3></td></tr>
          <tr>
            <td class="required"><label for="day[]"><?=$cwlang["timesegment"]["timesegDays"]?>:</label></td>
            <td colspan="3">
              <table class="timesegment">
              <tr >
                <td>1 <input type="checkbox" id="day[]" name="day[]" value="1" <?if (in_array("1",$day)) echo "checked=\"checked\""; ?>/></td> 
                <td>2 <input type="checkbox" id="day[]" name="day[]" value="2" <?if (in_array("2",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>3 <input type="checkbox" id="day[]" name="day[]" value="3" <?if (in_array("3",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>4 <input type="checkbox" id="day[]" name="day[]" value="4" <?if (in_array("4",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>5 <input type="checkbox" id="day[]" name="day[]" value="5" <?if (in_array("5",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>6 <input type="checkbox" id="day[]" name="day[]" value="6" <?if (in_array("6",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>7 <input type="checkbox" id="day[]" name="day[]" value="7" <?if (in_array("7",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>8 <input type="checkbox" id="day[]" name="day[]" value="8" <?if (in_array("8",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>9 <input type="checkbox" id="day[]" name="day[]" value="9" <?if (in_array("9",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>10 <input type="checkbox" id="day[]" name="day[]" value="10" <?if (in_array("10",$day)) echo "checked=\"checked\""; ?>/></td>
              </tr>
              <tr>
                <td>11 <input type="checkbox" id="day[]" name="day[]" value="11" <?if (in_array("11",$day)) echo "checked=\"checked\""; ?>/></td> 
                <td>12 <input type="checkbox" id="day[]" name="day[]" value="12" <?if (in_array("12",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>13 <input type="checkbox" id="day[]" name="day[]" value="13" <?if (in_array("13",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>14 <input type="checkbox" id="day[]" name="day[]" value="14" <?if (in_array("14",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>15 <input type="checkbox" id="day[]" name="day[]" value="15" <?if (in_array("15",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>16 <input type="checkbox" id="day[]" name="day[]" value="16" <?if (in_array("16",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>17 <input type="checkbox" id="day[]" name="day[]" value="17" <?if (in_array("17",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>18 <input type="checkbox" id="day[]" name="day[]" value="18" <?if (in_array("18",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>19 <input type="checkbox" id="day[]" name="day[]" value="19" <?if (in_array("19",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>20 <input type="checkbox" id="day[]" name="day[]" value="20" <?if (in_array("20",$day)) echo "checked=\"checked\""; ?>/></td>
              </tr>
              <tr>
                <td>21 <input type="checkbox" id="day[]" name="day[]" value="21" <?if (in_array("21",$day)) echo "checked=\"checked\""; ?>/></td> 
                <td>22 <input type="checkbox" id="day[]" name="day[]" value="22" <?if (in_array("22",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>23 <input type="checkbox" id="day[]" name="day[]" value="23" <?if (in_array("23",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>24 <input type="checkbox" id="day[]" name="day[]" value="24" <?if (in_array("24",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>25 <input type="checkbox" id="day[]" name="day[]" value="25" <?if (in_array("25",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>26 <input type="checkbox" id="day[]" name="day[]" value="26" <?if (in_array("26",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>27 <input type="checkbox" id="day[]" name="day[]" value="27" <?if (in_array("27",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>28 <input type="checkbox" id="day[]" name="day[]" value="28" <?if (in_array("28",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>29 <input type="checkbox" id="day[]" name="day[]" value="29" <?if (in_array("29",$day)) echo "checked=\"checked\""; ?>/></td>
                <td>30 <input type="checkbox" id="day[]" name="day[]" value="30" <?if (in_array("30",$day)) echo "checked=\"checked\""; ?>/></td>
              </tr>
              <tr>
                <td>31 <input type="checkbox" id="day[]" name="day[]" value="31" <?if (in_array("31",$day)) echo "checked=\"checked\""; ?>/></td> 
              </tr>
              </table>
            </td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><?=$cwlang["timesegment"]["timesegUnchecked"]?><hr/></td></tr>

          <tr><td></td><td colspan="3"><h3><?=$cwlang["timesegment"]["timesegMonths"]?></h3></td></tr>
          <tr>
            <td class="required"><label for="month[]"><?=$cwlang["timesegment"]["timesegMonths"]?>:</label></td>
            <td colspan="3">
              <table class="timesegment">
              <tr >
                <td><?=$cwlang["timesegment"]["timesegJan"]?> <input type="checkbox" id="month[]" name="month[]" value="1" <?if (in_array("1",$month)) echo "checked=\"checked\""; ?>/></td> 
                <td><?=$cwlang["timesegment"]["timesegFeb"]?> <input type="checkbox" id="month[]" name="month[]" value="2" <?if (in_array("2",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegMar"]?> <input type="checkbox" id="month[]" name="month[]" value="3" <?if (in_array("3",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegApr"]?> <input type="checkbox" id="month[]" name="month[]" value="4" <?if (in_array("4",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegMay"]?> <input type="checkbox" id="month[]" name="month[]" value="5" <?if (in_array("5",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegJun"]?> <input type="checkbox" id="month[]" name="month[]" value="6" <?if (in_array("6",$month)) echo "checked=\"checked\""; ?>/></td>
              </tr>
              <tr>
                <td><?=$cwlang["timesegment"]["timesegJul"]?> <input type="checkbox" id="month[]" name="month[]" value="7" <?if (in_array("7",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegAug"]?> <input type="checkbox" id="month[]" name="month[]" value="8" <?if (in_array("8",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegSep"]?> <input type="checkbox" id="month[]" name="month[]" value="9" <?if (in_array("9",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegOct"]?> <input type="checkbox" id="month[]" name="month[]" value="10" <?if (in_array("10",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegNov"]?> <input type="checkbox" id="month[]" name="month[]" value="11" <?if (in_array("11",$month)) echo "checked=\"checked\""; ?>/></td>
                <td><?=$cwlang["timesegment"]["timesegDec"]?> <input type="checkbox" id="month[]" name="month[]" value="12" <?if (in_array("12",$month)) echo "checked=\"checked\""; ?>/></td>
              </tr>
              </table>
            </td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><?=$cwlang["timesegment"]["timesegUnchkMonths"]?></td></tr>

        </table>
      </div>

    <div class="action">
      <?if (isset($_GET["id"])) {?><input type="hidden" name="id" value="<?=$id?>" /><?}?>
      <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-cancel.gif" alt="Cancel" onclick="location.href='../'; return false;"/>
      <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Save" />
    </div>
  </form>
 </div>  
  
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=$cwlang["isdngrp"]["sidebarTitle"]?></h1>
          <p><?=$cwlang["isdngrp"]["sidebarDesc"]?>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================

  $smarty->assign("section", "rules");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>

